import Config from '../config/config'
import { DefaultDataModel, FlatDataModel } from '../model/index'

/**
 * 获取规则链信息
 */
/**
 * 节点信息描述
 * 节点需要包含部分默认配置，防止左侧节点不存在时，已绘制的节点出现错误，此项为业务需求
 * @property additionalInfo 节点需要的扩展数据，默认数据来源于ruleNodeComponents中，该数据由前端生成
 * @property additionalInfo.component {string} 节点前端组件名称
 * @property additionalInfo.clazz {string} 节点后端处理逻辑
 * @property additionalInfo.inEnabled {boolean} 是否可被其他节点连接
 * @property additionalInfo.outEnabled {boolean} 是否可连接其他节点
 * @property additionalInfo.relationTypes {string[]} 当前节点连接到其他节点时的关系列表（？某些节点中可修改该选项？）
 */
function ruleChain(req, res) {
  const resData = {
    code: 200,
    msg: null,
    data: {
      ruleChainId: '6ee18ec8-49bc-ac9a-3859-4cff06309ba7',
      firstNodeIndex: 0,
      nodes: [
        {
          additionalInfo: {
            x: 90,
            y: 150,
            clazz: 'FrequencyLimitNode',
            visible: true,
            icon: 'startNode',
            component: 'ExternalNodeStartNode',
            inEnabled: false,
            outEnabled: true,
            editEnabled: false,
            removeEnabled: false,
            relationTypes: [],
            parent: 'start-stage-node',
            defaultConfiguration: null,
          },
          nodeId: '2bf9961d-3c45-d780-c00b-d2837d1b7813',
          nodeName: '开始节点',
          nodeDescription: '设置频率限制相关配置',
          nodeType: 'START_NODE',
          configuration: null,
          component: 'ExternalNodeStartNode',
        },
        {
          additionalInfo: {
            x: 450,
            y: 300,
            clazz: 'FrequencyLimitNode',
            visible: true,
            icon: 'frequencyNode',
            component: 'AdvancedLibFrequencyNode',
            inEnabled: true,
            outEnabled: true,
            editEnabled: true,
            removeEnabled: true,
            relationTypes: ['Success', 'Failure'],
            parent: 'start-stage-node',
            defaultConfiguration: null,
          },
          nodeId: '2bf9961d-3c45-d780-c00b-d2837d1b7813',
          nodeName: '频率限制',
          nodeDescription: '设置频率限制相关配置',
          nodeType: 'FLOW_NODE',
          configuration: {
            executeStrategy: 'currentStart',
            executeStrategyTimes: 2
          },
          component: 'AdvancedLibFrequencyNode',
        },
        {
          additionalInfo: {
            x: 90,
            y: 600,
            clazz: 'FrequencyLimitNode',
            visible: true,
            icon: 'endStartNode',
            component: 'ExternalNodeStartNode',
            inEnabled: false,
            outEnabled: true,
            editEnabled: false,
            removeEnabled: false,
            relationTypes: [],
            parent: 'end-stage-node',
            defaultConfiguration: null,
          },
          nodeId: '2bf9961d-3c45-d780-c00b-d2837d1b7813',
          nodeName: '开始节点',
          nodeDescription: '设置频率限制相关配置',
          nodeType: 'START_NODE',
          configuration: null,
          component: 'ExternalNodeStartNode',
        },
      ],
      connections: [
        {
          sourceNodeType: 'START_NODE',
          sourceNodeIndex: 0,
          targetNodeType: 'FLOW_NODE',
          targetNodeIndex: 1,
          connectType: 'none'
        }
      ],
      productDef: {
        productId: 'a693bbaa-0b2f-d5b2-c03a-be1cccc770fa',
        productName: '新IDE智能场景',
        versionId: '74da0a0e-4f12-207c-b6c0-8799b0ccc45f',
        versionName: '1.1',
        productType: '1',
        versionDescription: '789',
        versionStatus: '0',
        validityType: 'permanent',
        validityPeriod: {},
        oemList: [
          { oem: '广乘广州', oemId: '1', oemCode: 'GAC', series: 'A08', seriesId: '16', seriesCode: 'A08', model: 'A08-顶配尊容-1', modelId: '16000', modelCode: 'KT1D-0W9-00' },
          { oem: '广乘广州', oemId: '1', oemCode: 'GAC', series: 'A60', seriesId: '60', seriesCode: 'A60', model: 'A60-次顶配JU2A-0A8-00', modelId: '60006', modelCode: 'JU2A-0A8-00' },
          { oem: '广新', oemId: '2', oemCode: 'GACNE', series: 'A26', seriesId: '1', seriesCode: 'A26', model: 'A26-网约车北方版-孚能+日电产', modelId: '10', modelCode: 'G1FA2DA1CN20' },
        ],
        configuration: { vehicleSignal: null, ecologyData: null },
      },
      extendData: {
        validateResult: null,
        editMode: 'stage',
        phasenodeIndex: 3,
      }
    },
  }
  res.json(resData)
}

/**
 * 获取可用节点列表
 *
 */
/**
 * 节点结构描述
 * @property id {string} 节点后端生成的id
 * @property type {string} 节点分类。相同业务类型的节点属于同一分类。相同分类下，节点样式相同。
 * @property name {string} 节点的默认名称
 * @property description {string} 节点的默认描述
 * @property clazz {string} ！！！该属性可能会被删除！！！节点的后台处理逻辑，
 * @property configurationDescriptor {object} 节点前端配置项
 * @property configurationDescriptor.inEnabled {boolean} 是否可被其他节点连接
 * @property configurationDescriptor.outEnabled {boolean} 是否可连接其他节点
 * @property configurationDescriptor.relationTypes {string[]} 当前节点连接到其他节点时的默认关系列表
 * @property configurationDescriptor.visible {boolean} 节点是否可见
 */
function ruleNodeComponents(req, res) {
  const resData = [
    {
      name: '场景库',
      type: 'SCENE_NODE',
      icon: 'sceneLib',
      nodeGroup: [
        {
          name: '',
          nodeList: [
            {
              type: 'SCENE_NODE',
              name: '空白场景',
              icon: 'sceneLib',
              clazz: 'SceneTemplateNode',
              component: 'SceneLibSceneNode',
              description: '',
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: true,
                editEnabled: true,
                removeEnabled: true,
                visible: true,
                relationTypes: ['True', 'False'],
                defaultConfiguration: null,
              },
            },
            {
              type: 'SCENE_NODE',
              name: '前置条件',
              icon: 'frontConditionNode',
              clazz: 'SceneTemplateNode',
              component: 'SceneLibFrontConditionNode',
              description: '',
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: true,
                editEnabled: true,
                removeEnabled: false,
                visible: true,
                relationTypes: ['True', 'False'],
                defaultConfiguration: null,
              },
            },
            {
              type: 'SCENE_NODE',
              name: '自动触发',
              icon: 'autoTouchNode',
              clazz: 'SceneTemplateNode',
              component: 'SceneLibAutoTouchNode',
              description: '',
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: true,
                editEnabled: true,
                removeEnabled: true,
                visible: true,
                relationTypes: ['True', 'False'],
                defaultConfiguration: null,
              },
            },
            {
              type: 'SCENE_NODE',
              name: '主动触发',
              icon: 'manualTouchNode',
              clazz: 'SceneTemplateNode',
              component: 'SceneLibManualTouchNode',
              description: '',
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: true,
                editEnabled: true,
                removeEnabled: true,
                visible: true,
                relationTypes: ['True', 'False'],
                defaultConfiguration: null,
              },
            },
            {
              type: 'SCENE_NODE',
              name: '主动退出',
              icon: 'manualExitNode',
              clazz: 'SceneTemplateNode',
              component: 'SceneLibManualExitNode',
              description: '',
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: true,
                editEnabled: true,
                removeEnabled: true,
                visible: true,
                relationTypes: ['True', 'False'],
                defaultConfiguration: null,
              },
            },
          ],
        },
      ],
    },
    {
      name: '服务库',
      type: 'SERVICE_NODE',
      icon: 'serviceLib',
      nodeGroup: [
        {
          name: '',
          nodeList: [
            {
              type: 'SERVICE_NODE',
              name: '空白服务',
              icon: 'serviceLib',
              clazz: 'ServiceTemplateNode',
              component: 'ServiceLibServiceNode',
              description: '',
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: true,
                editEnabled: true,
                removeEnabled: true,
                visible: true,
                relationTypes: ['Success', 'Failure'],
                defaultConfiguration: null,
              },
            },
          ],
        },
      ],
    },
    {
      name: '生态服务',
      type: 'THIRD_NODE',
      icon: 'thirdLib',
      nodeGroup: [
        {
          name: '',
          nodeList: [
            {
              type: 'THIRD_NODE',
              name: '天气提醒',
              clazz: 'EcologyServiceNode',
              component: 'ThirdLibThirdNode',
              icon: 'thirdLib',
              description: null,
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: true,
                visible: true,
                editEnabled: true,
                removeEnabled: true,
                relationTypes: ['Success', 'Failure'],
                defaultConfiguration: {
                  metaModelId: 3,
                  serviceName: '天气提醒',
                  serviceKey: 'c',
                  templateId: '',
                },
              },
            },
            {
              type: 'THIRD_NODE',
              name: '恶劣天气提醒',
              clazz: 'EcologyServiceNode',
              component: 'ThirdLibThirdNode',
              icon: 'thirdLib',
              description: null,
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: true,
                visible: true,
                editEnabled: true,
                removeEnabled: true,
                relationTypes: ['Success', 'Failure'],
                defaultConfiguration: {
                  metaModelId: 4,
                  serviceName: '恶劣天气提醒',
                  serviceKey: 'd',
                  templateId: '',
                },
              },
            },
          ],
        },
      ],
    },
    {
      name: 'TSP服务',
      type: 'TSP_NODE',
      icon: 'tspLib',
      nodeGroup: [
        {
          name: '',
          nodeList: [
            {
              type: 'TSP_NODE',
              name: '远程充电控制',
              clazz: 'TspServiceNode',
              component: 'TspLibTspNode',
              icon: 'tspLib',
              description: null,
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: true,
                editEnabled: true,
                removeEnabled: true,
                visible: true,
                relationTypes: ['Success', 'Failure'],
                defaultConfiguration: {
                  metaModelId: '6288a8304d482c5308ccb298',
                  serviceName: '远程充电控制',
                  serviceKey: '6288a7ff1dfb371489072d3e/charge/v1/remoteCharge',
                  inputParams: [],
                },
              },
            },
            {
              type: 'TSP_NODE',
              name: '远程开关车窗接口',
              clazz: 'TspServiceNode',
              component: 'TspLibTspNode',
              icon: 'tspLib',
              description: null,
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: true,
                editEnabled: true,
                removeEnabled: true,
                visible: true,
                relationTypes: ['Success', 'Failure'],
                defaultConfiguration: {
                  metaModelId: '6288a8304d482c5308ccb297',
                  serviceName: '远程开关车窗接口',
                  serviceKey: '6288a7ff1dfb371489072d3e/carBody/v1/window/switch',
                  inputParams: [],
                },
              },
            },
          ],
        },
      ],
    },
    {
      name: '交互库',
      type: 'INTERACTIVE_NODE',
      icon: 'interactiveLib',
      nodeGroup: [
        {
          name: '',
          nodeList: [
            {
              type: 'INTERACTIVE_NODE',
              name: '弹窗交互',
              icon: 'dialogNode',
              clazz: 'PopupInteractionNode',
              component: 'InteractiveLibDialogNode',
              description: '车机弹窗显示交互内容',
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: true,
                editEnabled: true,
                removeEnabled: true,
                visible: true,
                relationTypes: ['Success', 'Failure'],
                defaultConfiguration: null,
              },
            },
          ],
        },
      ],
    },
    {
      name: '高级',
      type: 'ADVANCED_NODE',
      icon: 'advancedLib',
      nodeGroup: [
        {
          name: '流程控制',
          nodeList: [
            {
              type: 'FLOW_NODE',
              name: '并行开始',
              icon: 'parallelStartNode',
              clazz: 'AdvancedLibParallelStartNode',
              component: 'AdvancedLibParallelStartNode',
              description: '并行开始节点',
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: true,
                editEnabled: false,
                removeEnabled: true,
                visible: true,
                relationTypes: ['Success', 'Failure'],
                defaultConfiguration: null,
              },
            },
            {
              type: 'FLOW_NODE',
              name: '并行结束',
              icon: 'parallelEndNode',
              clazz: 'AdvancedLibParallelEndNode',
              component: 'AdvancedLibParallelEndNode',
              description: '并行结束节点',
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: true,
                editEnabled: true,
                removeEnabled: true,
                visible: true,
                relationTypes: ['Success', 'Failure'],
                defaultConfiguration: null,
              },
            },
            {
              type: 'FLOW_NODE',
              name: '结束节点',
              icon: 'endNode',
              clazz: 'EndNode',
              component: 'AdvancedLibEndNode',
              description: '结束节点',
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: false,
                editEnabled: false,
                removeEnabled: true,
                visible: true,
                relationTypes: ['Success', 'Failure'],
                defaultConfiguration: null,
              },
            },
            {
              type: 'FLOW_NODE',
              name: '频率限制',
              icon: 'frequencyNode',
              clazz: 'FrequencyLimitNode',
              component: 'AdvancedLibFrequencyNode',
              description: '设置频率限制相关配置',
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: true,
                editEnabled: true,
                removeEnabled: true,
                visible: true,
                relationTypes: ['Success', 'Failure'],
                defaultConfiguration: null,
              },
            },
            {
              type: 'FLOW_NODE',
              name: '延迟节点',
              icon: 'delayNode',
              clazz: 'AdvancedLibDelayNode',
              component: 'AdvancedLibDelayNode',
              description: '延迟节点',
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: true,
                editEnabled: true,
                removeEnabled: true,
                visible: true,
                relationTypes: ['Success', 'Failure'],
                defaultConfiguration: null,
              },
            },
          ],
        },
        {
          name: '高级功能',
          nodeList: [
            {
              type: 'ADVANCED_NODE',
              name: '状态变化',
              icon: 'stateChangeNode',
              clazz: 'FrequencyLimitNode',
              component: 'AdvancedLibStateChangeNode',
              description: '状态变化节点',
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: true,
                editEnabled: true,
                removeEnabled: true,
                visible: true,
                relationTypes: ['Success', 'Failure'],
                defaultConfiguration: null,
              },
            },
            {
              type: 'ADVANCED_NODE',
              name: '服务恢复',
              icon: 'serveBackNode',
              clazz: 'FrequencyLimitNode',
              component: 'AdvancedLibServeBackNode',
              description: '服务恢复节点',
              configurationDescriptor: {
                inEnabled: true,
                outEnabled: true,
                editEnabled: true,
                removeEnabled: true,
                visible: true,
                relationTypes: ['Success', 'Failure'],
                defaultConfiguration: null,
              },
            },
          ],
        },
      ],
    },
  ]

  res.json({ data: resData })
}

function setProductInfo(req, res) {
  const resData = DefaultDataModel({
    msg: '操作成功',
  })
  res.json(resData)
}

function checkRuleChainValid(req, res) {
  const resData = {
    code: 200,
    data: null,
    message: '信号无效',
  }
  res.json(resData)
}

const ResponseList = [
  {
    path: `${Config.baseURL}/design/business/ruleChain/:id/metaData`,
    method: 'get',
    fun: ruleChain,
  },
  {
    path: `${Config.baseURL}/design/business/componentGroups`,
    method: 'get',
    fun: ruleNodeComponents,
  },
  {
    path: `${Config.baseURL}/api/ruleChain/editProductVersion`,
    method: 'post',
    fun: setProductInfo,
  },
  {
    path: `${Config.baseURL}/design/business/object/checkValid`,
    method: 'post',
    fun: checkRuleChainValid,
  },
]

export default ResponseList
